from pathlib import Path

from pip._internal.utils.misc import format_size

d1 = r'M:\图\网图'
for p in Path(d1).glob('*.gif'):
    name = p.stem
    jpg = p.parent / (name + '.jpg')
    if jpg.exists():

        gif_size = p.stat().st_size
        jpg_size = jpg.stat().st_size
        print(jpg.name, format_size(gif_size), format_size(jpg_size))
        # if jpg_size < gif_size:
        #     jpg.unlink()
